package com.applets.yidiantong.controller;


import com.applets.yidiantong.pojo.AjaxResult;
import com.applets.yidiantong.pojo.News;
import com.applets.yidiantong.pojo.ServiceResult;
import com.applets.yidiantong.service.NewsService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 咨询类 前端控制器
 * </p>
 *
 * @author zhaoyang
 * @since 2020-10-20
 */
@RestController
@RequestMapping("/")
public class NewsController {

    @Autowired
    NewsService newsService;

    //查询咨询
    @ApiOperation("查询咨询")
    @RequestMapping("/searchNews")
    @ResponseBody
    public AjaxResult searchNews(
                                 @RequestParam(value = "page",defaultValue = "1") Integer page,
                                 @RequestParam(value = "limit",defaultValue = "30") Integer limit){

        ServiceResult<IPage<News>> serviceResult = newsService.searchNews(page, limit);
        if (serviceResult.isFlag()) {
            return  AjaxResult.success( (int) serviceResult.getData().getTotal(),serviceResult.getData().getRecords());
        } else {
            return  AjaxResult.error();
        }

    }
}

